Namespace definitions

Functions and properties that are only accessible withing the scope of an operation.

Example

operation my_operation() {
print(op_context.exists()); // Prints true
}

query my_query() {
return op_context.exists(); // Returns false
}

Since

0.7.0

Properties

Link copied to clipboard

The height of the block being built, i.e. the number of completed blocks in the blockchain.

For each block, the height is the number of blocks before it, therefore the first block in the chain has height 0, the second has height 1, etc.

Link copied to clipboard

Indicates whether there is currently an operation context, i.e. if the currently executing code has been called from an operation.

When false, accessing other properties and calling functions in this namespace will result in an exception being thrown. When true, other properties and functions in this namespace can be used safely.

Examples:

function main() {
print(op_context.exists); // prints false
}
operation main() {
print(op_context.exists); // prints true
}
Link copied to clipboard

The timestamp of the most recent completed block in the blockchain, in milliseconds.

The most recent completed block is the parent block of the block currently being built.

If there is no most recent completed block (i.e. if the first block in the blockchain is still being built), this will have the value -1.

In either case, this is a Unix epoch timestamp, i.e. the number of milliseconds that have elapsed since midnight on 1st January 1970.

Link copied to clipboard

The index of the current operation within the transaction.

The first operation in the transaction has index 0.

Functions

Link copied to clipboard
function emit_event(type: text, data: gtv)

Register an event for handling by the blockchain at the end of the current transaction.

Postchain allows a set of events to be triggered at the end of every transaction, after all operations have been executed. This function is used to trigger such an event. Handlers for these events, sometimes called event sinks, are registered with the block builder in Postchain extensions.

emit_event is used internally in several Chromia platform extensions such as ICMF and EIF.

Link copied to clipboard

Gets all operations in the current transaction.

Link copied to clipboard

Get a struct representing the current operation.

Link copied to clipboard

Get the signers of the current transaction.

Link copied to clipboard
function is_signer(pubkey: byte_array): boolean

Check if a given public key is a signer of the current transaction; i.e. if it's in the list of signers returned by op_context.get_signers().